/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reflection;

import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Nguyen Minh Tan
 */
class PrivateMethodClass{
    private String hello = "\n\nHello World ^^!\n\n";
    private void traceHello(){
        System.out.print(hello);
    }
}
public class AccessPrivateMethod {

    public AccessPrivateMethod(){
        try {
            PrivateMethodClass p = new PrivateMethodClass();
            Method fi = p.getClass().getDeclaredMethod("traceHello");//Lấy trường tĩnh tên hello
            fi.setAccessible(true);//Cài đặt cho phép truy nhập thuộc tính private
            fi.invoke(p);//
        } catch (Exception ex) {
            Logger.getLogger(AccessPrivateMethod.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void main(String arg[]){
        new AccessPrivateMethod();
    }

}
/*


Hello World ^^!

 * */